package cn.lqz.bucttrain.mapper;

import cn.lqz.bucttrain.annotations.AutoFill;
import cn.lqz.bucttrain.enums.OperationTypeEnum;
import cn.lqz.bucttrain.pojo.entity.User;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * 用户Mapper
 */
@Mapper
public interface UserMapper {

    /**
     * 查找
     * @param userId
     * @return
     */
    @Select("select * from user where user_id = #{userId}")
    User findByUserId(Long userId);

    /**
     * 查找
     * @param phoneNumber
     * @return
     */
    @Select("select * from user where phone_number=#{phoneNumber}")
    User findByPhoneNumber(String phoneNumber);
    /**
     * 查找
     * @param idCard
     * @return
     */
    @Select("select * from user where id_card=#{idCard}")
    User findByIdCard(String idCard);

    /**
     * 查找
     * @param phoneNumber
     * @param password
     * @return
     */
    @Select("select * from user where phone_number = #{phoneNumber} and password = #{password}")
    User findByPhoneNumberAndPassword(String phoneNumber,String password);


    /**
     * 修改
     * @param user
     */
    @AutoFill(OperationTypeEnum.UPDATE)
    void update(User user);

    /**
     * 插入
     * @param user
     */
    @AutoFill(OperationTypeEnum.INSERT)
    void insert(User user);

    /**
     * 分页查询
     * @param user
     * @return
     */
    Page<User> findBatch(User user);

    /**
     * 删除
     * @param userId
     */
    @Delete("delete from user where user_id=#{userId}")
    void deleteByUserId(Long userId);
}
